package com.sinothk.cloud.mq.rabbit;

import com.sinothk.cloud.mq.websocket.bean.IMBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@Api(tags = "RabbitMQ模块")
@RequestMapping("/rabbit")
@RestController
public class RabbitMqController {

    private final RabbitMqProducer producer;

    public RabbitMqController(RabbitMqProducer producer) {
        this.producer = producer;
    }

    @ApiOperation(value = "发送邮件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "email", value = "收件人邮箱地址", required = true),
            @ApiImplicitParam(name = "content", value = "消息内容", required = true)})
    @GetMapping("/sendEmail")
    public String sendEmail(@RequestParam(value = "email") String email, @RequestParam(value = "content") String content) {
        producer.send("test_queue");
        return "success";
    }

    @ApiOperation(value = "发送短信")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phoneNum", value = "收件人手机号码", required = true),
            @ApiImplicitParam(name = "content", value = "消息内容", required = true)})
    @GetMapping("/sendSms")
    public String sendSms(@RequestParam(value = "phoneNum") String phoneNum, @RequestParam(value = "content") String content) {
        producer.send("test_queue");
        return "success";
    }

    @ApiOperation(value = "发送实时消息")
    @PostMapping("/sendIM")
    public String sendIM(@RequestBody IMBean iMBean) {
        if (iMBean == null) {
            return "";
        }
        producer.sendIm(iMBean);
        return "success";
    }
}
